package com.prs.crm.dao.cdxh.impl;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.prs.crm.dao.cdxh.MaterialTeamDao;
import com.prs.crm.dao.impl.BaseDaoImpl;
import com.prs.crm.domain.cdxh.MaterialProduct;
import com.prs.crm.domain.cdxh.material.MaterialTeam;
import com.prs.crm.domain.cdxh.molding.Molding;

/**
 * @author LanXiaoGang
 * @E-mail:lan9liang@163.com
 * @qq:7857553326
 * @version 创建时间：2010-12-6 上午10:39:46
 * 简单说明
 */

public class MaterialTeamDaoImpl extends BaseDaoImpl<MaterialTeam> implements
		MaterialTeamDao {

	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public MaterialTeam getMaterialTeam(final String materialCode,final String planCodeNum) {
		return (MaterialTeam)this.getHibernateTemplate().execute(
			      new HibernateCallback() {   
						public Object doInHibernate(Session session) throws HibernateException {
				        	Criteria criteria = session.createCriteria(MaterialTeam.class);
				        	criteria.add(Restrictions.eq("materialCode", materialCode));
				        	criteria.add(Restrictions.eq("planCodeNum", planCodeNum));				        	
				        	List<MaterialTeam> result = criteria.list();
				        	if(result.size()==0){
				        		return null;
				        	}else{
				        		return result.get(0);
				        	}
				        }   
				 } );
	}

	@Override
	public void saveOrMaterialTeam(MaterialTeam materialTeam) {
		this.getHibernateTemplate().saveOrUpdate(materialTeam);
		
	}
	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public List<MaterialTeam> getMaterialTeamOrderpLan(final String orderplan) {
		return (List<MaterialTeam>)this.getHibernateTemplate().execute(
			      new HibernateCallback() {   
						public Object doInHibernate(Session session) throws HibernateException {
				        	Criteria criteria = session.createCriteria(MaterialTeam.class);
				        	criteria.add(Restrictions.eq("planCodeNum", orderplan));		        	
				        	List<MaterialTeam> result = criteria.list();				        	
				        		return result;				        	
				        }   
				 } );
	}

}
